﻿using System;
using System.Collections.Generic;
using Luna.Data.Configuration;
using Luna.Data.Test;
using NUnit.Framework;

namespace Luna.Data.CRM
{
    [TestFixture]
    public class AccountTest : DataWithReferenceTest<IContactProvider, IAccountData>
    {
        private const string ADDRESS_FORMAT = "Address";

        private const string CITY_FORMAT = "City";

        private const string COMMENT_FORMAT = "Comment";

        private const string COUNTRY_FORMAT = "Country";

        private const string MAIL_FORMAT = "Mail";

        private const string NAME_FORMAT = "Name";

        private const string PHONENUMBER_FORMAT = "Phonenumber";

        private const string URL_FORMAT = "Url";

        private const string ZIPCODE_FORMAT = "ZipCode";

        public AccountTest(string contextName)
            : base(contextName)
        {
        }

        public override Action<IReferenceData> Delete
        {
            get { return Service.AccountDelete; }
        }

        public override Predicate<IAccountData> DeletePredicate
        {
            get { return x => x.Name.StartsWith(TEST_PREFIX); }
        }

        public override Func<IReferenceData, IAccountData> Get
        {
            get { return Service.AccountGet; }
        }

        public override Func<IEnumerable<IAccountData>> GetAll
        {
            get { return Service.AccountGetAll; }
        }

        public override Action<IAccountData> Save
        {
            get { return Service.AccountSave; }
        }

        public override bool AreSame(IAccountData P_Entity1, IAccountData P_Entity2)
        {
            bool L_Return = base.AreSame(P_Entity1, P_Entity2);

            L_Return &= P_Entity1.PK == P_Entity2.PK;
            L_Return &= P_Entity1.Address == P_Entity2.Address;
            L_Return &= P_Entity1.City == P_Entity2.City;
            L_Return &= P_Entity1.Country == P_Entity2.Country;
            L_Return &= P_Entity1.Name == P_Entity2.Name;
            L_Return &= P_Entity1.Url == P_Entity2.Url;
            L_Return &= P_Entity1.ZipCode == P_Entity2.ZipCode;
            L_Return &= P_Entity1.Comment == P_Entity2.Comment;

            return L_Return;
        }

        public override IAccountData Create()
        {
            IAccountData L_Entity = base.Create();
            LoadEntity(L_Entity);
            L_Entity.Address = GetString(ADDRESS_FORMAT);
            L_Entity.City = GetString(CITY_FORMAT);
            L_Entity.Country = GetString(COUNTRY_FORMAT);
            L_Entity.Name = GetString(NAME_FORMAT);
            L_Entity.Url = GetString(URL_FORMAT);
            L_Entity.ZipCode = GetString(ZIPCODE_FORMAT, 5);
            L_Entity.Comment = GetString(COMMENT_FORMAT);
            return L_Entity;
        }

        [Test(Description = "Test of insert and get")]
        public new void TestInsertAndGet()
        {
            base.TestInsertAndGet();
        }
    }
}